import re
from typing import Dict


class Transfer(Dict):
    def __init__(self, info_str, name, num) -> None:
        self.info = info_str
        self["英雄名"] = name
        num == num if num else "SP"
        career = self.__match(f"(?<=\|)职业{num}=(.*?)(?=\n)")
        self["职业"] = career
        self["射程"] = self.__match(f"(?<=\|)职业{num}射程=(.*?)(?=\n)") if career else ""
        self["移动"] = self.__match(f"(?<=\|)职业{num}移动=(.*?)(?=\n)") if career else ""
        self["生命"] = self.__match(f"(?<=\|)职业{num}生命=(.*?)(?=\n)") if career else ""
        self["攻击"] = self.__match(f"(?<=\|)职业{num}攻击=(.*?)(?=\n)") if career else ""
        self["智力"] = self.__match(f"(?<=\|)职业{num}智力=(.*?)(?=\n)") if career else ""
        self["防御"] = self.__match(f"(?<=\|)职业{num}防御=(.*?)(?=\n)") if career else ""
        self["魔防"] = self.__match(f"(?<=\|)职业{num}魔防=(.*?)(?=\n)") if career else ""
        self["技巧"] = self.__match(f"(?<=\|)职业{num}技巧=(.*?)(?=\n)") if career else ""
        self["兵种"] = [
            self.__match(f"(?<=\|)职业{num}兵种=((.*?)(、(.*?))*?)(?=\n)").split("、")[0] if career else "",
            self.__match(f"(?<=\|)职业{num}兵种=((.*?)(、(.*?))*?)(?=\n)").split("、")[1] if career and self.__match(f"(?<=\|)职业{num}兵种=((.*?)(、(.*?))+?)(?=\n)") else ""
        ]
        self["技能"] = [
            self.__match(f"(?<=\|)职业{num}技能=((.*?)(、(.*?))*?)(?=\n)").split("、")[0] if career else "",
            self.__match(f"(?<=\|)职业{num}技能=((.*?)(、(.*?))*?(?=\n))").split("、")[1] if career and self.__match(f"(?<=\|)职业{num}技能=((.*?)(、(.*?))+?)(?=\n)") else ""
        ]

    def __match(self, format):
        value = re.search(format, self.info, re.MULTILINE)
        return value.group(1) if value else ""     
        